package com.wokeMy.view.adpter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wokeMy.view.model.RightModel;
import com.zhongcai.online.R;

import java.util.List;


public class MyRightAdapter extends BaseAdapter {
	private Context context;
	List<RightModel> list;
	String type;
	public MyRightAdapter(Context context, List<RightModel> models,String type) {
		super();
		this.context = context;
		this.list = models;
		this.type=type;
	}
	
	@Override
	public int getCount() {
		if (list!=null) {
			return list.size();
		}
		return 0;
	}

	@Override
	public Object getItem(int position) {
		if (list!=null) {
			return list.get(position);
		}
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHold viewHold;
		if (convertView==null) {
			viewHold=new ViewHold();
			convertView=LayoutInflater.from(context).inflate(R.layout.layout_right_item, null);
			viewHold.textView0=(TextView) convertView.findViewById(R.id.right_item_textview0);
			viewHold.textView1=(TextView) convertView.findViewById(R.id.right_item_textview1);
			viewHold.textView2=(TextView) convertView.findViewById(R.id.right_item_textview2);
			viewHold.textView3=(TextView) convertView.findViewById(R.id.right_item_textview3);
			viewHold.textView4=(TextView) convertView.findViewById(R.id.right_item_textview4);
			convertView.setTag(viewHold);
		}else {
			viewHold=(ViewHold) convertView.getTag();
		}
		switch (type) {
			case "6":
				viewHold.textView0.setTextColor(android.graphics.Color.RED);
				break;
			case "5":
				viewHold.textView1.setTextColor(android.graphics.Color.RED);
				break;
			case "4":
				viewHold.textView2.setTextColor(android.graphics.Color.RED);
				break;
			case "3":
				viewHold.textView3.setTextColor(android.graphics.Color.RED);
				break;
			case "2":
				viewHold.textView4.setTextColor(android.graphics.Color.RED);
				break;
			default:
				break;
		}
		viewHold.textView0.setText(list.get(position).getText0());
		viewHold.textView1.setText(list.get(position).getText1());
		viewHold.textView2.setText(list.get(position).getText2());
		viewHold.textView3.setText(list.get(position).getText3());
		viewHold.textView4.setText(list.get(position).getText4());
		return convertView;
	}
	
	static class ViewHold{
		
		TextView textView0,textView1,textView2,textView3,textView4;
	}

}
